#include "StdAfx.h"
#include "Tester.h"
#include "../NeuralBasic/Network.h"
#include "../MnistDigit/Digit.h"

namespace Recognition
{

	Tester::Tester(NeuralBasic::Network& network
		, std::vector<std::unique_ptr<MnistDigit::Digit>>& digits)
		: m_network(network)
		, m_digits(digits)
		, m_recognizedCount(0)
	{
	}


	Tester::~Tester(void)
	{
	}

	double Tester::Start()
	{
		m_recognizedCount = 0;
		for(auto it= m_digits.begin(), itEnd=m_digits.end()
			; it!=itEnd; ++it)
		{
			const std::unique_ptr<MnistDigit::Digit>& digit=*it;
			const std::vector<double>& output = m_network.Work(digit->GetInput());
			digit->SetOutput(output);
			if(digit->IsClassified())
				++m_recognizedCount;
		}
		return GetRecognitionRatio();
	}

	double Tester::GetRecognitionRatio() const
	{
		const double digitsCount = static_cast<double>(m_digits.size());
		const double ratio = m_recognizedCount/digitsCount*100;
		return ratio;
	}
}